package alterzhang.aspect;/**
 * @Author: 003089
 * @Description:
 * @Date: 2019/6/26 17:44
 */

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Author: 003089
 * @Description:
 * @Date: 2019/6/26 17:44
 */
@Aspect
@Component
public class TimeMonitoringAspect {

    @Pointcut("@annotation(alterzhang.annotation.TimeMonitoring)")
     public void timeMonitoringAspect(){

     }

    // 在这里定义前置切面
    @Before("timeMonitoringAspect()")
    public void beforeMethod(JoinPoint joinPoint) {
        // 这里执行保存日志的动作
        System.out.println("before method");
    }


    @Around("timeMonitoringAspect()")
    public Object around(ProceedingJoinPoint joinPoint) {
        try {
             Signature sign=   joinPoint.getSignature();
            String name= sign.getName();
           long start= System.currentTimeMillis();
           Object obj= joinPoint.proceed();
           long end= System.currentTimeMillis();
            System.out.println("==============name"+name+"===time:"+(end-start));
            return obj;
        } catch (Throwable e) {
            e.printStackTrace();
        }
           return  null;
    }

}
